package com.z.jdbc_demo;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidPooledConnection;

import java.sql.SQLException;

public class JdbcDataSourceExample {
    public static void main(String[] args) throws SQLException {
        // 获得连接池对象
        DruidDataSource druidDataSource = new DruidDataSource();
        druidDataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
        druidDataSource.setUrl("jdbc:mysql://127.0.0.1:3306/zk");
        druidDataSource.setUsername("root");
        druidDataSource.setPassword("123456");

        // 设置连接池
        druidDataSource.setInitialSize(5);
        druidDataSource.setMaxActive(10);

        // 从连接池中获取连接对象
        DruidPooledConnection connection = druidDataSource.getConnection();
        System.out.println(connection);

        // connection 进行CRUD

        // 回收
        connection.close();

    }
}

